package sg.edu.nus.iss.cerberus.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * @author Lin Naing Oo(A0079983E)
 * */

public abstract class CMethod implements Serializable{

	private String accessModifier;
	private String methodName;
	private ArrayList<String> parameters;
	
	public CMethod(String accessModi, String name, ArrayList<String> params){
		this.accessModifier = accessModi;
		this.methodName = name;
		this.parameters = params;
	}
	
	//get and set for accessModifier
	public void setAccessModifier(String accessModi){
		this.accessModifier = accessModi;
	}
	public String getAccessModifer(){
		return this.accessModifier;
	}
	
	//get and set for methodName
	public void setMethodName(String name){
		this.methodName = name;
	}
	public String getMethodName(){
		return this.methodName;
	}
	
	//get and set for parameterTypes
	public void setParameters(String param){
		this.parameters.add(param);
	}
	public String getParamters(int index){
		return this.parameters.get(index);
	}
	
	public String getParamterName(int index){
		String[] temp = this.getParamters(index).split("\\s");
		return temp[1];
	}
	
	public int getParametersCount(){
		if(parameters!=null)
		return this.parameters.size();
		else
			return -1;
	}
	
	public ArrayList<String> getParams(){
		return this.parameters;
	}
	
	//get individual parameter name
	public String getParameterNamesList(){
		StringBuffer buffer = new StringBuffer();

		for(int i = 0; i < getParametersCount(); i++){
			String[] temp = this.getParamters(i).split("\\s");
			buffer.append(temp[1]);
			
			//putting comma between
			if(i != getParametersCount()-1)
				buffer.append(",");
			}
		return buffer.toString();
	}
	
	//get parameter type at index
	public String getParameterType(int index){
		String[] temp = this.getParamters(index).split("\\s");
		return temp[0];
	}
	
}
